#include <iostream>
#include <cstring>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
using namespace std;

const string fifo = "./myfifo";
const mode_t mode = 0666;


int main()
{
    int rfd = open(fifo.c_str(),O_RDONLY);
    if(rfd == -1)
    {
        cout << "errno = " << errno << ", " << strerror(errno) << endl;
        exit(-1);
    }
    while(true)
    {
        char buf[64];
        int n = read(rfd,buf,sizeof(buf));
        if(n > 0)
        {
            cout << "client# " << buf << endl;
        }
        else if(n == 0)
        {
            cout << "写端关闭，我读端也关闭" << endl;
            break;
        }
        else
        {
            cout << "errno = " << errno << ", " << strerror(errno) << endl;
            exit(-1);
        }
    }
    close(rfd);
    return 0;
}